package com.zt.dev.siteInfoRegister.service.impl;

import com.zt.dev.physicalequipment.pojo.PhysicalEquipmentMessage;
import com.zt.dev.siteInfoRegister.mapper.SiteMapper;
import com.zt.dev.siteInfoRegister.pojo.Site;
import com.zt.dev.siteInfoRegister.pojo.SiteUse;
import com.zt.dev.siteInfoRegister.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class SiteServiceImpl implements SiteService {

    @Autowired
    private SiteMapper siteMapper;

    @Override
    public void register(Site site) {
        siteMapper.insertSite(site);
    }

    @Override
    public int addPhysicalEquipmentMessage(PhysicalEquipmentMessage physicalEquipmentMessage) {
        int index = siteMapper.insertPhysicalEquipmentMessage(physicalEquipmentMessage);
        return index;
    }

    @Override
    public List<Site> getAll() {
        return siteMapper.selectAll();
    }

    @Override
    public Site getById(Integer id) {
        return siteMapper.selectById(id);
    }

    @Override
    @Transactional
    public int removeById(Integer id) {
        siteMapper.deleteUseById(id);
        return siteMapper.deleteById(id);
    }

    @Override
    @Transactional
    public int modifyById(Site site) {

        int index = siteMapper.insertSiteUse(site.getLength(),site.getWidth(),site.getId());
        return siteMapper.modifyById(site);
    }

    @Override
    public List<Site> getAllPage(Integer currentPage, Integer pageSize) {
        Integer total = (currentPage-1)*pageSize;
        return siteMapper.selectAllPage(total,pageSize);
    }

    @Override
    public List<SiteUse> getAllSiteUseById(Integer id) {
        return siteMapper.getAllSiteUseById(id);
    }
}
